package ai.george.mcpclient.controller;


import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.rag.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "网络信息获取mcp示例")
@RestController
@RequestMapping("/webpage-mcp")
public class WebPagMcpController {


    private final ChatClient chatClient;

    public WebPagMcpController(ChatClient.Builder builder, ToolCallbackProvider toolCallbackProvider) {

        this.chatClient = builder
                .defaultOptions(DashScopeChatOptions.builder().withTemperature(0.7).build())
                .defaultToolCallbacks(toolCallbackProvider.getToolCallbacks()) // 添加工具回调
                .build();
    }


    /**
     *  网页爬虫MCP
     * @param question
     * @return
     */
    @GetMapping("/page-mcp")
    public String ragQuery(@RequestParam(name = "question", defaultValue = "帮我总结下面网页中的内容：https://juejin.cn/post/7325338405409570868") String question) {
        // 该chatClient已经配备了RAG能力
        return chatClient
                .prompt()
                .system("你是一个网页爬取专家，你可以运用工具爬取指定网页的内容并且进行总结")
                .user(question)
                .tools()
                .call()
                .content();
    }



}
